/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { CompileModeEnum } from '../../enum/compile-mode-enum.js';
import { Named, Option, RequiredNamed } from '../options.js';
import { AppJson } from './app-json-options.js';
import { ConfigJson } from './config-json-options.js';

export namespace ModuleJson {
  import AppObj = AppJson.AppObj;
  import UrisObj = ConfigJson.UrisObj;
  import TestRunnerObj = ConfigJson.TestRunnerObj;

  export interface SkillsObj {
    actions?: string[];
    entities?: string[];
    uris?: UrisObj[];
    permissions?: string[];
    domainVerify?: boolean;
  }

  export interface AbilityObj extends RequiredNamed {
    srcEntrance?: string;
    srcEntry?: string;
    description?: string;
    icon?: string;
    label?: string;
    orientation?: string;
    visible?: boolean;
    skills?: SkillsObj[];
    launchType?: string;
    moduleName?: string;
    startWindow?: string;
    metadata?: MetadataObj[];
  }

  export interface FormObj extends RequiredNamed {
    updateEnabled: boolean;
    scheduledUpdateTime?: number;
    updateDuration?: number;
    supportDimensions: string[];
    defaultDimension: string;
    codeLanguage?: string;
  }

  export interface FormsObj extends Option {
    forms: FormObj[];
  }

  export interface MetadataObj extends Named {
    resource?: string;
    value?: string;
  }

  export interface UsedSceneObj extends Option {
    abilities?: string[];
    when?: string;
  }

  export interface RequestPermissionObj extends RequiredNamed {
    reason?: string;
    usedScene?: UsedSceneObj;
  }

  export interface DependencyObj {
    moduleName: string;
    bundleName?: string;
    versionCode?: number;
  }

  export interface AtomicServiceObj {
    preloads: {
      moduleName: string;
    };
  }

  export interface ExtensionAbilityObj extends RequiredNamed {
    srcEntrance?: string;
    srcEntry?: string;
    icon?: string;
    description?: string;
    type: string;
    visible?: boolean;
    metadata?: MetadataObj[];
  }

  export interface ModuleObj extends RequiredNamed {
    type: string;
    srcEntrance?: string;
    srcEntry?: string;
    description?: string;
    mainElement?: string;
    deviceTypes: string[];
    deliveryWithInstall?: boolean;
    installationFree?: boolean;
    pages: string;
    routerMap: string;
    appStartup: string;
    systemTheme?: string;
    abilities?: AbilityObj[];
    extensionAbilities?: ExtensionAbilityObj[];
    virtualMachine?: string;
    compileMode?: CompileModeEnum;
    metadata?: MetadataObj[];
    requestPermissions?: RequestPermissionObj[];
    definePermissions?: DefinePermissionsObj[];
    dependencies?: DependencyObj[];
    libIsolation?: boolean;
    atomicService?: AtomicServiceObj;
    proxyData?: ProxyDataObj[];
    testRunner?: TestRunnerObj
  }

  export interface DefinePermissionsObj extends Named {
    grantMode?: string;
    availableLevel?: string;
    provisionEnable?: boolean;
    distributedSceneEnable?: boolean;
    label?: string;
    description?: string;
  }

  export interface ProxyDataObj {
    uri: string;
    requiredReadPermission: string;
    requiredWritePermission: string;
    metadata: MetadataObj;
  }

  export interface ShortcutsObj {
    shortcutId: string;
    label: string;
    icon: string;
    wants: WantsObj[];
  }

  export interface WantsObj {
    bundleName: string | undefined;
    abilityName: string;
  }

  export interface ModuleOptObj {
    module: ModuleObj;
    app: AppObj;
  }
}
